package com.sicnu.ssj.controller;

import com.sicnu.ssj.pojo.Result;
import com.sicnu.ssj.utils.JwtUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RequestMapping("/article")
@RestController
public class ArticleController {
    @GetMapping("/list")
    public Result<String> list(@RequestHeader("Authorization") String token, HttpServletResponse response){
        try {//验证token
            Map<String, Object> claims = JwtUtil.parseToken(token);
            return Result.success("文章列表");
        } catch (Exception e) {
            //http响应码401，未授权
            response.setStatus(401);
            return Result.error("未登录");
        }
    }
}

